from django.db import models
import datetime
from django.utils import timezone
# Create your models here.

##############################################################################
#为博客准备的模型
class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    def __str__(self):              # __unicode__ on Python 2
        return self.name

class Author(models.Model):
    name = models.CharField(max_length=200)
    email = models.EmailField()

    def __str__(self):              # __unicode__ on Python 2
        return self.name

class Entry(models.Model):
    blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
    headline = models.CharField(max_length=255)
    body_text = models.TextField(null=True)
    pub_date = models.DateField(null=True)
    mod_date = models.DateField(null=True)
    authors = models.ManyToManyField(Author,null=True)
    n_comments = models.IntegerField(null=True)
    n_pingbacks = models.IntegerField(null=True)
    rating = models.IntegerField(null=True)

    def __str__(self):              # __unicode__ on Python 2
        return self.headline
    def get_absolute_url(self):
        return "/blog/oldsite/%i" %self.id #这里为的是实现重定向， 当用户访问新站/1，时会自动跳到oldsite/1下去。